home *** CD-ROM | disk | FTP | other *** search
- Path: news.kth.se!news
- From: Anders Olsson <aolsson@struct.kth.se>
- Newsgroups: comp.lang.c++
- Subject: OO design issue
- Date: 9 Jan 1996 13:06:43 GMT
- Message-ID: <4ctp93$2gu@news.kth.se>
- NNTP-Posting-Host: lotus.ce.kth.se
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
-
- I accidently posted the last message before I got to my point
- (never write messages in a window where you have a "Post it" keycombination:-)
-
- I'll try again:
-
- I have some questions about how to design relations between a class and
- its member classes.
-
- I can simplify my problem to the following three classes:
-
- class Node
- {
- public:
- double GetXCoordinate();
- private:
- double XCoordinate;
- };
-
- class Triangle
- {
- public:
- double CalculateArea();
- private:
- int nNodeIndex[3]; // Index into node vector
- };
-
- class TrianglesAndNodes
- {
- double GetXCoordinate(int NodeNr);
- private:
- vector<Node> NodeVector;
- vector<Triangle> TriangleVector;
- };
-
- The TrianglesAndNodes class is a world of nodes and triangles, and it contains two vectors of Node:s, and Triangle:s.
- The Triangle has a method that calculates its own area.
- However, it has only information about the index of the nodes it is connected to.
- So to get the necessary coordinates the Triangle instance can use the GetXCoordinate method,
- defined in TrianglesAndNodes. The problem is how to reach the TrianglesAndNodes instance
- from the Triangle instance.
- Is there a recommended way to do this is?
-
- ---
- Anders Olsson
- Stockholm, Sweden
-